#pragma once
#include <vector>
#include "CLeastSquareMethod.h"
class ControlPointDlg;

class ControlPoint
{
public:
	explicit ControlPoint(int a);

	ControlPointDlg* ConpointDlg;

	struct ControlPointList
	{
		CPoint BasePoint;
		CPoint WarpPoint;
	};

	std::vector<ControlPointList> m_ControlPointList;
	std::vector<ControlPointList> m_TempControlPointList;

	void GetPoint();
	void PushInPoint(CPoint BasePoint, CPoint WarpPoint);

	void DrawPoint();

	void DeletePoint(int iNum);

	inline static ControlPoint& GetInstance() {
		return _singleton;
	}

	CLeastSquareMethod LSM;
	int nIndex;
	void CalculateLSM(int i);
	void CalculatePre(CPoint point, double& Xresult, double& Yresult, int order);

	int iCoefficient;
	double * pBaseX;
	double * pBaseY;
	double * pWarpX;
	double * pWarpY;
	double * coeffs;

	void OutputBmp(CString strOutputPath);

	void Init_BitMap_FileHeader(int nWidth, int nHeight, int colorbit, BITMAPFILEHEADER* pbmfh, BITMAPINFOHEADER* pbmih);

	BITMAPFILEHEADER    bmfh;
	BITMAPINFOHEADER    bmih;

	void PredictPoint(int order);

	void PutoutControlPoint(CString strFileOut);
	void PutinControlPoint(CString strFileIn, int iInflag);

private:
	static ControlPoint _singleton;
	~ControlPoint();
};


#include "ControlPointDlg.h"
